<template>
    <div>
        <Card>
            <Tabs value="name1" @on-click="selectTab">
                <TabPane label="我的收益" name="name1" >
                    <Table 
                        :height="$app.winHeight-235" 
                        :columns="columns1" 
                        :data="data1" 
                        :loading="loading"
                        stripe
                        border
                        class="marginB10"
                    ></Table>
                    <div class="page">
                        <Page :total="total"
                            show-total
                            show-elevator
                            show-sizer
                            size="small"
                              :page-size="pageSize"
                              :page-size-opts="$app.pageAll.pageSizeOpts"
                              :current = 'page'
                              @on-change="loadMore"
                              @on-page-size-change="changePageSize"
                        ></Page>
                    </div>
                </TabPane>
                <TabPane label="提现记录" name="name2">
                    <Table 
                        :height="$app.winHeight-235" 
                        :columns="columns2" 
                        :data="data2" 
                        :loading="loading"
                        stripe
                        border
                        class="marginB10"
                    ></Table>
                    <div class="page">
                        <Page :total="total" show-sizer size="small"
                              :page-size="pageSize"
                              :page-size-opts="$app.pageAll.pageSizeOpts"
                              :current = 'page'
                              @on-change="loadMore2"
                              @on-page-size-change="changePageSize2"
                        ></Page>
                    </div>
                </TabPane>
            </Tabs>
        </Card>
    </div>
</template>

<script>
    export default {
        name: "earnings",
        data () {
            return {
                loading:true,
                page: 1, // 当前页数
                pageSize: $app.pageAll.pageSize, // 默认数据返回条数
                total: 0, // 所有数据条数
                total_page: 0, // 所有页面
                columns1: [
                    {
                        title: '订单编号',
                        key: 'order_no',
                        width:280,
                        resizable: true,
                    },
                    {
                        title: 'ID / 手机号',
                        key: 'member_mobile',
                        width:140,
                        resizable: true,
                    },
                    {
                        title: '类别',
                        key: 'member_level_name',
                        align:'center',
                        width:130,
                        filters: [
                            {
                                label: '合伙人收益',
                                value: 1
                            },
                            {
                                label: '代理人收益',
                                value: 2
                            },
                            {
                                label: '会员收益',
                                value: 3
                            }
                        ],
                        filteredValue:[],
                        filterMultiple: false,
                        filterRemote: this.filterRemote
                    },
                    {
                        title: '收入类型',
                        key: 'type_name',
                        resizable: true,
                    },
                    {
                        title: '收入金额',
                        key: 'profit'
                    },
                    {
                        title: '日期',
                        key: 'created_at'
                    }
                ], // 收益列
                data1: [], // 收益记录
                columns2: [
                    {
                        title: '申请时间',
                        key: 'created_at',
                        width:200,
                        resizable: true,
                    },
                    {
                        title: '提现金额',
                        key: 'money',
                        width:150,
                        resizable: true,
                    },
                    {
                        title: '银行名称',
                        key: 'blank_name',
                    },
                    {
                        title: '银行账户',
                        key: 'blank_account',
                    },
                    {
                        title: '状态',
                        key: 'state_name',
                        width:150,
                        resizable: true,
                    }
                ], // 提现列
                data2: [], // 提现记录
                member_type:0 // 下级成员等级(1合伙人,2代理,3普通会员), 0或不传为全部
            }
        },
        created () {
          this.getProfitList();
        },
        methods:{
            // 获取收益记录
            getProfitList () {
                const page = this.page;
                const pageSize = this.pageSize;
                const member_type = this.member_type;
                
                this.loading=true;
                $ajax.lb_getProfitList({page,pageSize,member_type}, res => {
                    this.loading=false;
                    this.data1 = res.data.list;
                    this.total = res.data.total;
                    this.total_page = res.data.total_page;
                });
            },
            // 获取提现申请列表
            getWithdrawalList () {
                
                const page = this.page;
                const pageSize = this.pageSize;

                this.loading=true;
                $ajax.lb_getWithdrawalList({page,pageSize}, res => {
                    this.loading=false;
                    this.data2 = res.data.list;
                    this.total = res.data.total;
                    this.total_page = res.data.total_page;
                });
            },
            selectTab (name) {
                if (name == 'name1') {
                    // 我的收益
                    this.page =1;
                    this.getProfitList();
                }else if (name == 'name2') {
                    // 我的提现
                    this.page =1;
                    this.getWithdrawalList();
                }else {

                }
            },
            filterRemote: function (value,row) {
                // this.status = value;
                // this.startQuery();
                console.log(value[0]);
                this.member_type = value[0];
                // 我的收益
                this.page =1;
                this.getProfitList();
            },

            // 加载更多
            loadMore (page) {
                this.page = page;
                this.getProfitList()
            },
            // 数据返回条
            changePageSize(pageSize) {
                this.pageSize = pageSize;
                this.getProfitList()
            },
            // 加载更多
            loadMore2 (page) {
                this.page = page;
                this.getWithdrawalList()
            },
            // 数据返回条
            changePageSize2(pageSize) {
                this.pageSize = pageSize;
                this.getWithdrawalList()
            },
        }
    }
</script>

<style scoped>

</style>